<template>
    <base-breadcrumb>
        <a-card class="mb20">
            <titleName :title="form.meetingName"></titleName>
            <a-form-model
                ref="ruleForm"
                :model="form"
                :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                :wrapperCol="{ lg: { span: 16 }, sm: { span: 16 } }"
            >
                <a-row :gutter="24">
                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="所属公司：">
                            <BaseInput disabled placeholder="加载中" v-model="form.branchComName"></BaseInput>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="所属项目：">
                            <BaseInput disabled placeholder="加载中" v-model="form.projectName"></BaseInput>
                        </a-form-model-item>
                    </a-col>

                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="讲评方案：">
                            <BaseInput disabled placeholder="加载中" v-model="form.commentedPlan"></BaseInput>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="编制人员：">
                            <BaseInput disabled placeholder="加载中" v-model="form.programmer"></BaseInput>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="评审日期：">
                            <BaseInput disabled placeholder="加载中" v-model="form.startTime"></BaseInput>
                        </a-form-model-item>
                    </a-col>

                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="讲解人：" prop="branchComId">
                            <BaseInput disabled placeholder="加载中" v-model="form.speaker"></BaseInput>
                        </a-form-model-item>
                    </a-col>

                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="填报人员：" prop="branchComId">
                            <BaseInput disabled placeholder="加载中" v-model="form.creatorName"></BaseInput>
                        </a-form-model-item>
                    </a-col>

                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="参会人数：">
                            <span class="flex">
                                <BaseInput style="width:100%" disabled placeholder="加载中" v-model="form.meetingCount"></BaseInput>
                                <a-button class="ml20" type="primary" @click="signInVsible = true">查看签到</a-button>
                                <a-button   v-if="
                                        form.meetingTypeCategory != 7 &&
                                        form.meetingTypeCategory != 8 &&
                                        form.meetingTypeCategory != 9 &&
                                        form.status != 35 &&
                                        form.status != 40
                                    " class="ml20" type="primary" @click="handlePage">会议大屏</a-button>
                            </span>
                        </a-form-model-item>
                    </a-col>
                     <a-col :md="24" :sm="24">
                        <a-form-model-item label="其他评审人员：" prop="otherReviewer">
                            <BaseTextarea disabled placeholder="请输入" v-model="form.otherReviewer" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
            </a-form-model>
        </a-card>
        <seeSign
            :visible="signInVsible"
            :id="id"
            @cancel="signInVsible = false"
            @confirm="signInVsible = false"
        ></seeSign>
        <a-card class="mb20">
            <titleName title="打分情况"></titleName>
            <s-table
                ref="table"
                size="default"
                rowKey="key"
                :columns="columns"
                :data="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                :showPagination="false"
            ></s-table>
        </a-card>

        <div class="tool-btns page-btn-right-top" v-if="pageType !== 'look'">
            <a-button v-if="pageType == 'start'" type="primary" :loading="loading.START" @click="handleSave('START')"
                >开始会议</a-button
            >
            <a-button v-else type="primary" :loading="loading.SUBMITTED" @click="handleSave('SUBMITTED')"
                >结束填报</a-button
            >
            <a-button type="primary" @click="handleClose">关闭</a-button>
        </div>
        <div class="tool-btns page-btn-right-top" v-else>
            <a-button type="primary" @click="handleClose">关闭</a-button>
        </div>
    </base-breadcrumb>
</template>
<script>
import { STable } from '@/components'
import { getMeeting, meetingSummary, colseMeeting, getMeetingScore, startMeeting } from '@/api/office/conference'
import seeSign from '@/components/seeSign'
const columns = [
    {
        title: '打分人员',
        dataIndex: 'scorer',
    },
    {
        title: '打分',
        dataIndex: 'score',
    },
    {
        title: '评审意见',
        dataIndex: 'opinions',
        width: '60%',
    },
]

export default {
    name:'a'+Date.now(),    components: {
        STable,
        seeSign,
    },
    data() {
        return {
            signInVsible: false,
            columns,
            pageType: '',
            form: {},
            id: '',
            loading: {
                DELETE: false,
                DRAFT: false,
                SUBMITTED: false,
                IMPORT: false,
                START: false,
            },
            loadData: async (parameter) => {
                if (this.id) {
                    const requestParameters = Object.assign({}, parameter, { meetingId: this.id })
                    const [err, res] = await getMeetingScore(requestParameters)
                    return new Promise((resolve, reject) => {
                        if (err) {
                            reject(err)
                        } else {
                            resolve(res)
                        }
                    })
                }
            },
        }
    },
    mounted() {
        if (this.$route.query.id) {
            this.id = this.$route.query.id
            this.pageType = this.$route.query.pageType
            console.log(this.id)
            this.getMeeting()
            this.initTitle()
        }
    },
    methods: {
        initTitle() {
            if (this.pageType == 'look') {
                this.$route.meta.title = '会议详情'
            } else {
                this.$route.meta.title = '会议进行中'
            }
        },
        async getMeeting() {
            const [err, res] = await getMeeting({ id: this.id })
            if (!err) {
                this.form = res.data
                this.$refs.table.refresh(true)
            }
        },

        async handleSave(status) {
            this.loading[status] = true
            if (this.pageType == 'start') {
                const [err, res] = await startMeeting({ id: this.id })
                this.loading[status] = false
                this.$message.success('成功')
                this.pageType = 'edit'
                this.getMeeting()
                this.initTitle()
                return
            }
            const [err, res] = await colseMeeting({ meetingId: this.id })
            this.loading[status] = false
            if (!err) {
                this.$message.success('成功')
                this.handleClose()
            }
        },
        handleClose() {
            this.$multiTab.close(this.$route.fullpath)
        },
        handlePage() {
            let routeData = this.$router.resolve({
                path: '/conference/standardConference/conferenceList/conferenceScreen',
                query: {
                    id: this.id,
                },
            })
            window.open(routeData.href, '_blank')
        },
    },
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
.tool-btns {
    display: flex;
    justify-content: flex-end;
    @{deep} .ant-btn + .ant-btn {
        margin-left: 12px;
    }
}
.flex {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    height: 40px;
}
</style>